package offer;

import java.util.Arrays;

public class offerII_0049 {
    public int sumNumbers(TreeNode root) {
        int[] sum=new int[1];
        sum(sum,root,0);
        return sum[0];
    }
    public void sum(int[] sum,TreeNode node,int current){
        if(node.left==null&&node.right==null){
            sum[0]+=10*current+node.val;
            return;
        }
        if(node.left!=null){
            sum(sum,node.left,10*current+node.val);
        }
        if(node.right!=null){
            sum(sum,node.right,10*current+node.val);
        }
    }
}
